//
//  SDEditPaientInfoData.m
//  SKinDiary
//
//  Created by pcyang on 16/7/12.
//  Copyright © 2016年 tencent. All rights reserved.
//

#import "SDEditPaientInfoData.h"

@implementation SDEditPaientInfoData
-(NSString*)getFullURL
{
    if (_editable) {
        return [NSString stringWithFormat:@"%@/patient/%ld",[[SDServerSwitchManager sharedInstance] getServerUrl],(long)_paientInfoItem.pId];
    } else {
        return [NSString stringWithFormat:@"%@/patient",[[SDServerSwitchManager sharedInstance] getServerUrl]];
    }
}

-(NSString*)getHTTPMethod
{
    return HTTP_PUT_METHOD;
}

-(NSDictionary*) getPostDictionary
{
    NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:6];
    [dict setObject:[NSNumber numberWithLong:_paientInfoItem.pId] forKey:@"id"];
    [dict setObject:[_paientInfoItem.cId safeString] forKey:@"cId"];
    [dict setObject:[_paientInfoItem.name safeString]forKey:@"name"];
    [dict setObject:[_paientInfoItem.gender safeString] forKey:@"gender"];
    [dict setObject:[_paientInfoItem.dateOfBirth safeString] forKey:@"dateOfBirth"];
    [dict setObject:[_paientInfoItem.avatar safeString] forKey:@"avatar"];
    
    return dict;
}

+(id)modelFromResponseValues:(id)infos error:(NSError**)error
{
    return infos;
}

- (id)resetWithResponseModel:(id)data
{
    if([data isKindOfClass:[NSDictionary class]])
    {
        if (_editable) {
            NSArray* patients = [data objectForKey:@"patients"];
            if (CHECK_VALID_ARRAY(patients)) {
                [patients objectAtIndex:0];
                _paientInfoItem = [[SDPaientInfoItem alloc] initWithInfo:[patients objectAtIndex:0]];
            }
        } else {
            _paientInfoItem = [[SDPaientInfoItem alloc] initWithInfo:[data objectForKey:@"patients"]];
        }
        
    }
    
    return data;
}
@end
